import Vue from 'vue';
import Router from 'vue-router';
import Taiqu from '@/components/Taiqu';
import TaiquInfo from '@/components/TaiquInfo';
import Machine from '@/components/Machine';
import MachineInfo from '@/components/MachineInfo';
import MachineData from '@/components/MachineData';
import TaiquData from '@/components/TaiquData';
import Statistics from '@/components/Statistics';
import TaiquDetail from '@/components/TaiquDetail';
import TaiquChangeRecord from '@/components/TaiquChangeRecord';
import Login from '@/components/Login';
import Logs from '@/components/Logs';
import User from '@/components/User';
import MachineChangeRecord from '@/components/MachineChangeRecord';
import UserForm from '@/components/UserForm';
import Yitai from '@/components/Yitai';

Vue.use(Router);
const router = new Router({
  routes: [{
    path: '/',
    name: 'Yitai',
    component: Yitai
  }, {
    path: '/taiqu',
    name: 'Taiqu',
    component: Taiqu,
    meta: {
      keepAlive: false
    }
  }, {
    path: '/taiquInfo',
    name: 'TaiquInfo',
    component: TaiquInfo
  }, {
    path: '/machine',
    name: 'Machine',
    component: Machine
  }, {
    path: '/machineInfo',
    name: 'MachineInfo',
    component: MachineInfo
  }, {
    path: '/machineData',
    name: 'MachineData',
    component: MachineData
  }, {
    path: '/taiquData',
    name: 'TaiquData',
    component: TaiquData
  }, {
    path: '/statistics',
    name: 'Statistics',
    component: Statistics
  }, {
    path: '/taiquDetail',
    name: 'TaiquDetail',
    component: TaiquDetail
  }, {
    path: '/taiquChangeRecord',
    name: 'TaiquChangeRecord',
    component: TaiquChangeRecord
  }, {
    path: '/login',
    name: 'Login',
    component: Login
  }, {
    path: '/logs',
    name: 'Logs',
    component: Logs
  }, {
    path: '/user',
    name: 'User',
    component: User
  }, {
    path: '/machineChangeRecord',
    name: 'MachineChangeRecord',
    component: MachineChangeRecord
  }, {
    path: '/userForm',
    name: 'UserForm',
    component: UserForm
  }]
});

router.beforeEach((to, from, next) => {
  const toDepth = to.path.split('/').length
  const fromDepth = from.path.split('/').length
  if (toDepth < fromDepth) {
    from.meta.keepAlive = false
    to.meta.keepAlive = true
  }
  next()
})


export default router
